//
//  ClassRoomDetailViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2017/12/12.
//  Copyright © 2017年 史宵宵. All rights reserved.
//

#import "ClassRoomDetailViewController.h"
#import "ClassDetailTableViewCell.h"
#import "SendFriendCircleViewController.h"
#import "XXAVPlayer.h"
#import "PayActivityInforViewController.h"

@interface ClassRoomDetailViewController ()<XXAVPlayerDelegate>
//@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic,strong) NSDictionary *homeworkDic;//作业的信息
@property (nonatomic,strong) ClassRoomInfo *classRoomInfo;
@property (nonatomic,weak) XXAVPlayer *playView;
@property (nonatomic,weak) UIView *bgView;
@property (nonatomic,weak) UISlider *slider;
@property (nonatomic,weak) UILabel *timeLabel;
@property (nonatomic,assign) BOOL isPlay;
@end

@implementation ClassRoomDetailViewController
//-(NSMutableArray *)dataArray{
//    if (!_dataArray) {
//        _dataArray = [NSMutableArray array];
//    }
//    return _dataArray;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ClassDetailTableViewCell class]) bundle:nil] forCellReuseIdentifier:@"ClassDetailTableViewCell"];
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem rightBarButtonItemWithImage:[UIImage imageNamed:@"img_back"] highlighted:[UIImage imageNamed:@"img_back"] target:self selector:@selector(back)];
    self.isPlay = NO;
    [self creatDataList];
    
}
- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)creatData{
    [self initVideoView];
    [self initSlider];
    
    self.title = self.classRoomInfo.course_name;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, 0, 30, 40);
    button.tag = 9000;
    [button addTarget:self action:@selector(collectionClassRoom:) forControlEvents:UIControlEventTouchUpInside];
    button.adjustsImageWhenHighlighted = NO;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [button setImage:[self.classRoomInfo.favourite_history isEqualToString:@"1"]?[UIImage imageNamed:@"class_collection"]:[UIImage imageNamed:@"class_disCollection"] forState:UIControlStateNormal];
    button.imageView.contentMode=UIViewContentModeScaleAspectFit;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
//    [self.dataArray addObject:self.classRoomInfo];
}
#pragma mark - 提交作业按钮
- (void)addHomeWorkView{
    self.tableView.frame = CGRectMake(0, 0, kScreenW, kScreenH - 64 - 40);
    
    UIButton *addButton = [[UIButton alloc]init];
    addButton.frame = CGRectMake(0, kScreenH - 64 - 40, kScreenW, 40);
    addButton.backgroundColor = KBACKNAVIGATIONCOLOR;
    [addButton setTitle:@"提交作业" forState:UIControlStateNormal];
//    [addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    addButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [addButton addTarget:self action:@selector(addHomeWork) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addButton];
}
#pragma mark - 提交作业页面
- (void)addHomeWork{
    SendFriendCircleViewController *sendFriendCircleVC = [[ SendFriendCircleViewController alloc]init];
    sendFriendCircleVC.sendType = KSendHomeWork;
    sendFriendCircleVC.titleStr = @"提交作业";
    sendFriendCircleVC.courseId = self.courseId;
    sendFriendCircleVC.placeholderStr = @"请上传你的作业......";
    __weak typeof (self)unself = self;
    sendFriendCircleVC.sendFriendCircleBlock = ^(){
        [unself creatDataList];
    };
    [self.navigationController pushViewController:sendFriendCircleVC animated:YES];
}
#pragma mark - 获取课程详情
- (void)creatDataList{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:@"1" forKey:@"page"];   //页数 默认1
    [dic setValue:KREFRESHROWS forKey:@"rows"];   //每页数量
    [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
    [dic setValue:self.courseId forKey:@"courseId"];    //课程id
    [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppCourseGetCourseDetail] andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            self.homeworkDic = [NSDictionary dictionaryWithDictionary:response];
            NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:self.homeworkDic[@"course"]];
            [dic setObject:response[@"buyHistory"] forKey:@"buyHistory"];
            self.classRoomInfo  = [ClassRoomInfo mj_objectWithKeyValues:dic];
            if ( [self.homeworkDic[@"homeworkHistory"] isEqualToString:@"0"] && !strIsEmpty(self.homeworkDic[@"course"][@"homework"])) { //用户满意提交作业，布置的作业不为空，则显示提交作业按钮
                [self addHomeWorkView];
            }
            [self creatData];
            [self.tableView reloadData];
        }
    }];
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.homeworkDic.allKeys.count) {
        if ( [self.homeworkDic[@"homeworkHistory"] isEqualToString:@"0"] && strIsEmpty(self.homeworkDic[@"course"][@"homework"])) {
            return 2;
        }
        return [self.homeworkDic[@"homeworkHistory"] isEqualToString:@"1"]?4:3;
    }
    return 2;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section && !self.homeworkDic.allKeys.count) {
        return 0;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!indexPath.section) {
        ClassDetailTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ClassDetailTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.classRoomInfo = self.classRoomInfo;
        __weak typeof(self) unself=self;
        cell.payClassBlack = ^(ClassRoomInfo *classRoomInfo) {
            PayActivityInforViewController *payActivityInforVC = [[PayActivityInforViewController alloc]init];
            payActivityInforVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            payActivityInforVC.moneyStr = unself.classRoomInfo.source_price;
            payActivityInforVC.numId = [NSString stringWithFormat:@"%@",unself.classRoomInfo.course_id];
            payActivityInforVC.titleStr = unself.classRoomInfo.course_name;
            payActivityInforVC.payType = @"course";
            payActivityInforVC.paySuccessBlack = ^{
                [unself initVideoView];
            };
            UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
            [appRootVC presentViewController:payActivityInforVC animated:YES completion:^{
                
            }];
        };
        return cell;
    }else if (indexPath.section == self.tableView.numberOfSections - 1){
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UIImageView *commentImageView=[[UIImageView alloc]initWithFrame:CGRectMake( 0, 0, 20, 20)];
            commentImageView.tag = 2000;
            commentImageView.contentMode=UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:commentImageView];
        }
        NSArray *imageArray = [NSArray arrayWithArray:self.homeworkDic[@"teacher_content"]];
        UIImageView *commentImageView = [cell.contentView viewWithTag:2000];
        if (!imageArray.count || strIsEmpty(imageArray[0])) {
            commentImageView.frame=CGRectZero;
            [self removeallSubViews:commentImageView];
        }
        else
        {
            commentImageView.frame= CGRectMake(0, 0, kScreenW, imageArray.count? imageArray.count*kScreenW * 2 : 0);
            for (int i=0; i < imageArray.count; i++) {
                UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, kScreenW * 2 * i, kScreenW, kScreenW * 2)];
                [imageView sd_setImageWithURL:[NSURL URLWithString:imageArray[i]] placeholderImage:KRECOMMENDLISTDEFAULT];
                imageView.tag=100+i;
                imageView.backgroundColor= [UIColor clearColor];
                imageView.contentMode=UIViewContentModeScaleToFill;
                [commentImageView addSubview:imageView];
            }
        }
        return cell;
    }
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel *label = [[UILabel  alloc]init];
        label.tag = 1000;
        label.font = [UIFont systemFontOfSize:14];
        label.numberOfLines = 0;
        [cell.contentView addSubview:label];
        
        UIImageView *commentImageView=[[UIImageView alloc]initWithFrame:CGRectMake( kScreenW - 20 - 25, 12, 20, 20)];
        commentImageView.tag = 1001;
        commentImageView.contentMode=UIViewContentModeScaleAspectFit;
        [cell.contentView addSubview:commentImageView];
    }
    NSString *titleStr = strIsEmpty(self.homeworkDic[@"course"][@"homework"])?@"":self.homeworkDic[@"course"][@"homework"];
    NSArray *imageArray = [NSArray arrayWithArray:self.homeworkDic[@"homework_image"]];
    if ([self.homeworkDic[@"homeworkHistory"] isEqualToString:@"1"] && indexPath.section == 2) {
        titleStr = strIsEmpty(self.homeworkDic[@"courseHomework"][@"context"])?@"":self.homeworkDic[@"courseHomework"][@"context"];
        imageArray = [NSArray arrayWithArray:self.homeworkDic[@"image_list"]];
    }
    UILabel *label = [cell.contentView viewWithTag:1000];
    label.text = titleStr;
    label.frame = CGRectMake(10, 10, kScreenW - 20, [Global getSizeOfString:titleStr maxWidth:kScreenW - 20 maxHeight:CGFLOAT_MAX withFontSize:14.6].height + 10) ;

    UIImageView *commentImageView = [cell.contentView viewWithTag:1001];
    if (!imageArray.count || strIsEmpty(imageArray[0])) {
        commentImageView.frame=CGRectZero;
        [self removeallSubViews:commentImageView];
    }
    else
    {
        commentImageView.frame= CGRectMake(10, CGRectGetMaxY(label.frame), kScreenW - 20, imageArray.count? (imageArray.count / 3)*( kScreenW-60)/3.0 : 0);
        for (int i=0; i < imageArray.count; i++) {
            UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake((( kScreenW-60)/3.0 + 15) * (i%3), (( kScreenW-60)/3.0 + 15) * (i / 3), ( kScreenW-60)/3.0, ( kScreenW-60)/3.0)];
            [imageView sd_setImageWithURL:[NSURL URLWithString:imageArray[i]] placeholderImage:KRECOMMENDLISTDEFAULT];
            imageView.tag=100+i;
            imageView.backgroundColor= [UIColor clearColor];
            imageView.contentMode=UIViewContentModeScaleToFill;
            [commentImageView addSubview:imageView];
        }
    }
    return cell;
}
/**
 *  移除视图
 *
 *  @param supView 父视图
 */
- (void )removeallSubViews:(UIView *)supView{
    for (id obj in supView.subviews) {
        [obj removeFromSuperview];
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == self.tableView.numberOfSections - 1){
        return [self.homeworkDic[@"teacher_content"] count] * kScreenW * 2;
    }else if (indexPath.section && self.homeworkDic.allKeys.count) { //有数据
        NSString *titleStr = strIsEmpty(self.homeworkDic[@"course"][@"homework"])?@"":self.homeworkDic[@"course"][@"homework"];//题目的标题
        NSArray *imageArray = [NSArray arrayWithArray:self.homeworkDic[@"homework_image"]];
        if ([self.homeworkDic[@"homeworkHistory"] isEqualToString:@"1"] && indexPath.section == 2) {
            titleStr = strIsEmpty(self.homeworkDic[@"courseHomework"][@"context"])?@"":self.homeworkDic[@"courseHomework"][@"context"];
            imageArray = [NSArray arrayWithArray:self.homeworkDic[@"image_list"]];
        }
        double titleHeight = [Global getSizeOfString:titleStr maxWidth:kScreenW - 20 maxHeight:CGFLOAT_MAX withFontSize:14.6].height + 20;
        double imageHeight = imageArray.count? ((imageArray.count -1) / 3 + 1)*(( kScreenW-60)/3.0 + 10 ): 0;
        
        return titleHeight + imageHeight + 20;
    }
    return [tableView fd_heightForCellWithIdentifier:@"ClassDetailTableViewCell" cacheByIndexPath:indexPath configuration:^(ClassDetailTableViewCell* cell) {
        cell.classRoomInfo = self.classRoomInfo;
    }];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (!section || ([self.homeworkDic[@"homeworkHistory"] isEqualToString:@"1"] && section == 2) ) {
        UIView *view = [[UIView alloc]init];
        view.frame = CGRectMake(0, 0, kScreenW, 0.01);
        view.backgroundColor = KBACKGROUNDCOLOR;
        
        return view;
    }
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, kScreenW, 44);
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *sepLabel = [[UILabel alloc]init];
    sepLabel.frame = CGRectMake(0, 10, 3, 24);
    sepLabel.backgroundColor = KBACKNAVIGATIONCOLOR;
    [view addSubview:sepLabel];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.frame = CGRectMake(10, 12, kScreenW - 20, 20);
    titleLabel.text = section == self.tableView.numberOfSections-1 ?@"课程详情": @"作业";
    titleLabel.font = [UIFont systemFontOfSize:16];
    [view addSubview:titleLabel];
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (!section  ||  ([self.homeworkDic[@"homeworkHistory"] isEqualToString:@"1"] && section == 2)) {
        return 0.01;
    }
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = KBACKGROUNDCOLOR;
    
    if ([self.homeworkDic[@"homeworkHistory"] isEqualToString:@"1"] && section == 1) {
        view.frame = CGRectMake(0, 0, kScreenW, 0.01);
        return view;
    }
    view.frame = CGRectMake(0, 0, kScreenW, 10.01);
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if ([self.homeworkDic[@"homeworkHistory"] isEqualToString:@"1"] && section == 1) {
        return 0.01f;
    }

    return 10.01f;
}
#pragma mark - 收藏 / 取消收藏
- (void)collectionClassRoom:(UIButton*)sender{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:self.courseId forKey:@"courseId"];   //动态的topicId 赞目标id
    [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
    
    NSString *url = [self.classRoomInfo.favourite_history isEqualToString:@"1"]? [JSPathUtil urlAppCourseDeleteFavourite]: [JSPathUtil urlAppCourseSetFavourite];
    
    [yjNetWorkManger requestType:POST andURL:url andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            [Global showActivityWithView:self.view withText:[self.classRoomInfo.favourite_history isEqualToString:@"1"]?@"取消收藏成功":@"收藏成功"];
            self.classRoomInfo.favourite_history = [self.classRoomInfo.favourite_history isEqualToString:@"1"]?@"0":@"1";
            [sender setImage:[self.classRoomInfo.favourite_history isEqualToString:@"1"]?[UIImage imageNamed:@"class_collection"]:[UIImage imageNamed:@"class_disCollection"] forState:UIControlStateNormal];
        }
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)initVideoView {
    if (![self.classRoomInfo.buyHistory isEqualToString:@"2"] && self.isPlay) {
        NSString *path = self.classRoomInfo.videoUrl;
        CGRect rect = CGRectMake(0, 0, self.view.bounds.size.width, 210);
        
        XXAVPlayer *playView = [[XXAVPlayer alloc] initWithFrame:rect];
        playView.backgroundColor = [UIColor clearColor];
        playView.userInteractionEnabled = YES;
        playView.delegate = self;
        
        self.tableView.tableHeaderView = playView;
        self.playView = playView;
        NSString *videoPath = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *url = [NSURL URLWithString:videoPath];
        [playView setupPlayerWith:url];
        
        if ([self.classRoomInfo.buyHistory isEqualToString:@"2"]) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:rect];
            [imageView sd_setImageWithURL:[NSURL URLWithString:self.classRoomInfo.logo] placeholderImage:KLIVECLASSDEFAULT];
            [self.playView addSubview:imageView];
        }else{
            [playView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(isHiddenSlider)]];
        }
    }else{
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.userInteractionEnabled = YES;
        imageView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 210);
        [imageView sd_setImageWithURL:[NSURL URLWithString:self.classRoomInfo.logo] placeholderImage:KRECOMMENDLISTDEFAULT];
        
        UIButton *isVideoButton = [[UIButton alloc]init];
        isVideoButton.frame = CGRectMake((kScreenW - 50)/2, (210-50)/2, 50, 50);
        [isVideoButton setImage:[UIImage imageNamed:@"class_live_begin"] forState:UIControlStateNormal];
        [isVideoButton addTarget:self action:@selector(isBuyHistory) forControlEvents:UIControlEventTouchUpInside];
        [imageView addSubview:isVideoButton];
        
        self.tableView.tableHeaderView = imageView;
    }
}

- (void)isBuyHistory{
    if (![self.classRoomInfo.buyHistory isEqualToString:@"2"]){
        self.isPlay = YES;
        [self creatData];
    }else{
         [Global showActivityWithView:self.view withText:@"您还没有购买"];
    }
}
- (void)isHiddenSlider{
    self.bgView.hidden = !self.bgView.hidden;
}
- (void)initSlider{
    
    UIView *bgView = [[UIView alloc]init];
    bgView.frame = CGRectMake(0, CGRectGetMaxY(self.playView.frame) - 50, kScreenW, 50);
    bgView.backgroundColor = rgba(169, 169, 169, 0.5);
    bgView.hidden = NO;
    self.bgView = bgView;
    [self.playView addSubview:bgView];
    
    UIButton *button = [[UIButton alloc]init];
    button.frame = CGRectMake(20, 15, 20, 20);
    button.titleLabel.font = [UIFont fontWithName:@"IconFont" size: 16.0];
    [button setTitle:@"\U0000e616" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.tag = 5000;
    [button addTarget:self action:@selector(beganPlayer:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:button];
    
    UISlider *mySlider = [[UISlider alloc] initWithFrame:CGRectMake(50, 10,kScreenW - 150 ,30) ];//高度设为40就好,高度代表手指触摸的高度.这个一定要注意
    mySlider.minimumValue = 0.0;//下限
    mySlider.maximumValue = 50.0;//上限
    mySlider.value = 0;//开始默认值
    mySlider.backgroundColor =[UIColor clearColor];//测试用,
    [mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    mySlider.continuous = NO;//当放开手., 值才确定下来
    [bgView addSubview:mySlider ];
    self.slider = mySlider;
    
    UILabel *timeLabel = [[UILabel alloc]init];
    timeLabel.frame = CGRectMake(CGRectGetMaxX(mySlider.frame) + 5, 15, 120, 20);
    timeLabel.font = [UIFont systemFontOfSize:12];
    timeLabel.textColor = [UIColor whiteColor];
    [ bgView addSubview:timeLabel];
    self.timeLabel = timeLabel;
}
- (void)sliderValueChanged:(UISlider *)slider{
    MyLog(@"%f",slider.value);
    [self.playView seekPlayerTimeTo:slider.value];
}
- (void)beganPlayer:(UIButton *)sender{
    [sender setTitle:[sender.titleLabel.text isEqualToString:@"\U0000e616"]?@"\U0000e700":@"\U0000e616" forState:UIControlStateNormal];
    [sender.titleLabel.text isEqualToString:@"\U0000e616"] ? [self.playView play]:[self.playView pause];
}
// LPAVPlayer delegate  ----- 状态提示
- (void)promptPlayerStatusOrErrorWith:(LPAVPlayerStatus)status
{
    switch (status) {
        case LPAVPlayerStatusLoadingVideo:// 开始准备
            
            //            [self.activity startAnimating];
            
            break;
            
        case LPAVPlayerStatusReadyToPlay:{// 准备完成
            
            //            [self.activity stopAnimating];
            //            [self.playOrPause setTitle:@"暂停" forState:UIControlStateNormal];
                        self.slider.maximumValue = self.playView.totalTime;
                        self.slider.value = 0;
            //            self.loadProgress.progress = 0;
        }
            break;
            
            
            
        default:
            break;
    }
}
// LPAVPlayer delegate  ----- 刷新数据
- (void)refreshDataWith:(NSTimeInterval)totalTime Progress:(NSTimeInterval)currentTime LoadRange:(NSTimeInterval)loadTime
{
    
    //    [self.loadProgress setProgress:(loadTime/totalTime) animated:YES];
    //
        [self.slider setValue:currentTime animated:YES];
    //
        self.timeLabel.text = [NSString stringWithFormat:@"%@/%@",[self otherConvertTimeFormat:currentTime],[self otherConvertTimeFormat:totalTime]];
}

- (NSString *)otherConvertTimeFormat:(NSInteger)time
{
    NSString *needStr = @"";
    
    if (time < 3600) {
        
        needStr =  [NSString stringWithFormat:@"%02li:%02li",lround(floor(time/60.f)),lround(floor(time/1.f))%60];
        
    } else {
        
        needStr =  [NSString stringWithFormat:@"%02li:%02li:%02li",lround(floor(time/3600.f)),lround(floor(time%3600)/60.f),lround(floor(time/1.f))%60];
        
    }
    return needStr;
}
- (void)enterPayView{
    PayActivityInforViewController *payActivityInforVC = [[PayActivityInforViewController alloc]init];
    payActivityInforVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    payActivityInforVC.moneyStr = self.classRoomInfo.source_price;
    payActivityInforVC.numId = [NSString stringWithFormat:@"%@",self.classRoomInfo.course_id];
    payActivityInforVC.titleStr = self.classRoomInfo.course_name;
    payActivityInforVC.payType = @"course";
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    [appRootVC presentViewController:payActivityInforVC animated:YES completion:^{
        
    }];
}
#pragma mark - 销毁 release
- (void)dealloc
{
        NSLog(@"--- %@ --- 销毁了",[self class]);



}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.tableView=nil;
    self.playView=nil;

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
